package com.basker.pisces.core.operator;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.basker.pisces.spring.SpringApplicationContext;

@Configuration
public class CompareOperatorManager {

    private static final String HANDLER_CLASS_PACKAGE = "com.basker.pisces.core.operator.handler.";

    public static CompareOperator getOperator(String operatorId) {
        return SpringApplicationContext.getInstance().getBean(operatorId, CompareOperator.class);
    }

    @Bean(CompareOperatorConstants.DATE_BETWEEN)
    public SqlCompareOperator dateBetween() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_BETWEEN);
        operator.setName("BETWEEN ? AND ?");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateRangeCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.DATE_EQUAL)
    public SqlCompareOperator dateEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_EQUAL);
        operator.setName("=");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.DATE_GREATER)
    public SqlCompareOperator dateGreater() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_GREATER);
        operator.setName(">");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.DATE_GREATER_EQUAL)
    public SqlCompareOperator dateGreaterEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_GREATER_EQUAL);
        operator.setName(">=");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.DATE_LESS)
    public SqlCompareOperator dateLess() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_LESS);
        operator.setName("<");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.DATE_LESS_EQUAL)
    public SqlCompareOperator dateLessEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_LESS_EQUAL);
        operator.setName("<=");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.DATE_NOT_EQUAL)
    public SqlCompareOperator dateNotEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.DATE_NOT_EQUAL);
        operator.setName("<>");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlDateCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.IN)
    public SqlCompareOperator in() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.IN);
        operator.setName("IN");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlInCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.IS_NOT_NULL)
    public SqlCompareOperator isNotNull() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.IS_NOT_NULL);
        operator.setName("IS NOT NULL");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlNullCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.IS_NULL)
    public SqlCompareOperator isNull() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.IS_NULL);
        operator.setName("IS NULL");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlNullCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.NOT_IN)
    public SqlCompareOperator notIn() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NOT_IN);
        operator.setName("NOT IN");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlInCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_BETWEEN)
    public SqlCompareOperator numberBetween() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_BETWEEN);
        operator.setName("BETWEEN ? AND ?");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlNumberRangeCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_EQUAL)
    public SqlCompareOperator numberEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_EQUAL);
        operator.setName("=");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_GREATER)
    public SqlCompareOperator numberGreater() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_GREATER);
        operator.setName(">");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_GREATER_EQUAL)
    public SqlCompareOperator numberGreaterEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_GREATER_EQUAL);
        operator.setName(">=");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_LESS)
    public SqlCompareOperator numberLess() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_LESS);
        operator.setName("<");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_LESS_EQUAL)
    public SqlCompareOperator numberLessEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_LESS_EQUAL);
        operator.setName("<=");

        return operator;
    }

    @Bean(CompareOperatorConstants.NUMBER_NOT_EQUAL)
    public SqlCompareOperator numberNotEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.NUMBER_NOT_EQUAL);
        operator.setName("<>");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_BEGIN)
    public SqlCompareOperator stringBegin() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_BEGIN);
        operator.setName("LIKE");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlStringBeginCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_END)
    public SqlCompareOperator stringEnd() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_END);
        operator.setName("LIKE");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlStringEndCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_EQUAL)
    public SqlCompareOperator stringEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_EQUAL);
        operator.setName("=");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_LIKE)
    public SqlCompareOperator stringLike() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_LIKE);
        operator.setName("LIKE");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlStringLikeCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_NOT_BEGIN)
    public SqlCompareOperator stringNotBegin() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_NOT_BEGIN);
        operator.setName("NOT LIKE");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlStringBeginCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_NOT_END)
    public SqlCompareOperator stringNotEnd() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_NOT_END);
        operator.setName("NOT LIKE");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlStringEndCompareOperatorHandler");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_NOT_EQUAL)
    public SqlCompareOperator stringNotEqual() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_NOT_EQUAL);
        operator.setName("<>");

        return operator;
    }

    @Bean(CompareOperatorConstants.STRING_NOT_LIKE)
    public SqlCompareOperator stringNotLike() {
        SqlCompareOperator operator = new SqlCompareOperator();

        operator.setOperatorId(CompareOperatorConstants.STRING_NOT_LIKE);
        operator.setName("NOT LIKE");
        operator.setOperatorHandlerClass(HANDLER_CLASS_PACKAGE + "SqlStringLikeCompareOperatorHandler");

        return operator;
    }
}
